package com.example.wm.common;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.sql.SQLIntegrityConstraintViolationException;

@ControllerAdvice(annotations = {Controller.class,RestController.class})
@ResponseBody
public class GlobalEception {
    @ExceptionHandler(SQLIntegrityConstraintViolationException.class)
    public R<String> ExceptionHandler(SQLIntegrityConstraintViolationException ex){

        if(ex.getMessage().contains("Dupling")){
               String[] split=ex.getMessage().split(" ");
                String msg=split[2];
                return R.error(msg);
        }
               return R.error("失败");
    }
     @ExceptionHandler(IllegalArgumentException.class)
     public R<String> StringIndexOutOfBoundsExceptionHandler(IllegalArgumentException ex){


         return R.error(ex.getMessage());
     }
    @ExceptionHandler(ArithmeticException.class)
    public R<String> Exceptionthe(ArithmeticException ex){
     String msg= ex.getMessage();
        return R.error(msg);
    }
}
